package com.bhs.sansong.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bhs.sansong.ui.dialog.MyClickListener;

/**
 * @data on 2020/10/16 6:26 PM
 * @auther armstrong
 * @describe 倒计时工具类
 */
public class CountDownTimerUtils extends CountDownTimer {
    private TextView mTextView;

    public CountDownTimerUtils(TextView textView, long millisInFuture) {
        super(millisInFuture, 1000);
        this.mTextView = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setText(DateUtils.timeParse(millisUntilFinished));  //设置倒计时时间
    }

    @Override
    public void onFinish() {
        mTextView.setText("00.00");
        if (listener != null) {
            listener.onClick(null);
        }
    }

    private MyClickListener listener;

    public void setMyClickListener(@Nullable MyClickListener l) {
        this.listener = l;
    }
}